' *** Documentation
' 
' Visual Basic Recursive Print
' 
' last updated: Jun 2007
' author: klenwell@gmail.com
' 
' FUNCTIONS
' 	vbPrintR(vVar)
' 
' NOTES
' 	Produces result similar to PHP's printr function
' 
' ____________________________________________________________________________*/

' *** LIBRARY CONSTANTS

' *** LIBRARY GLOBALS
dim iDrilledDown

' Var Settings
iDrilledDown = 0

' Function
Function vbPrintR(ByVal vVar, sName)

	On Error Resume Next

	' Return
	'Dim vbPrintR
	vbPrintR = "" 
	
	' Name
	If isEmpty(sName) Then: sName = "Variable": End If
	If ( iDrilledDown = 0 ) Then
		vbPrintR = "vbPrintR :: " & sName & vbNewLine & vbNewLine
	End If
	
	' Debug
	'MsgBox("Drilled Down : " & iDrilledDown)

	' Add Tabs
	Dim sTabPrt, iTabs
	sTabPrt = ""
	iTabs = iDrilledDown
	Do While iTabs > 0
		sTabPrt = sTabPrt & vbTab
		iTabs = iTabs - 1
	Loop
	vbPrintR = vbPrintR & sTabPrt
	
	iDrilledDown = iDrilledDown + 1
	
	' Is Array
	If IsArray(vVar) Then
		Dim vEl
		vbPrintR = vbPrintR & "Array: " & vbNewLine
		For Each vEl In vVar
			vbPrintR = vbPrintR & vbPrintR(vEl, Null)
		Next
	
	' Is Dictionary Object
	ElseIf IsObject(vVar) Then
		Dim sObjType, vKey
		sObjType = TypeName(vVar)
		If sObjType = "Dictionary" Then
			vbPrintR = vbPrintR & "Dictionary Object: " & vbNewLine			
			For Each vKey In vVar
				vbPrintR = vbPrintR & sTabPrt & vbTab & vKey & " : " & vVar.Item(vKey) & vbNewLine
			Next
		Else
			vbPrintR = vbPrintR & "Object : " & sObjType & vbNewLine
		End If
	
	' Other Var
	Else
		Dim sVarType
		sVarType = TypeName(vVar)
		vbPrintR = vbPrintR & sVarType & " : " & vVar & vbNewLine
	End If
	
	iDrilledDown = iDrilledDown - 1

End Function

'MsgBox("printr is loaded")

